package com.culturalCenter.dataCenter.mapper.volunteer;


import com.culturalCenter.dataCenter.customEntity.volunteer.CustomVolunteerActivity;
import com.culturalCenter.dataCenter.customEntity.volunteer.CustomVolunteerActivityCount;
import com.culturalCenter.dataCenter.entity.volunteer.CdcVolunteerActivity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 志愿者活动信息(CdcVolunteerActivity)表数据库访问层
 *
 * @author makejava
 * @since 2021-09-17 16:12:12
 */
@Mapper
public interface CdcVolunteerActivityMapper {

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     *
     * @return 实例对象
     */
    CdcVolunteerActivity queryById(@Param("id") String id);

    /**
     * 查询指定行数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     *
     * @return 对象列表
     */
    List<CdcVolunteerActivity> queryAllByLimit(@Param("offset") int offset, @Param("limit") int limit);

    /**
     * 通过实体作为筛选条件查询
     *
     * @param cdcVolunteerActivity 实例对象
     *
     * @return 对象列表
     */
    List<CdcVolunteerActivity> queryAll(CdcVolunteerActivity cdcVolunteerActivity);

    /**
     * 新增数据
     *
     * @param cdcVolunteerActivity 实例对象
     *
     * @return 影响行数
     */
    int insert(CdcVolunteerActivity cdcVolunteerActivity);

    /**
     * 批量新增数据（MyBatis原生foreach方法）
     *
     * @param entities List<CdcVolunteerActivity> 实例对象列表
     *
     * @return 影响行数
     */
    int insertBatch(@Param("entities") List<CdcVolunteerActivity> entities);

    /**
     * 批量新增或按主键更新数据（MyBatis原生foreach方法）
     *
     * @param entities List<CdcVolunteerActivity> 实例对象列表
     *
     * @return 影响行数
     */
    int insertOrUpdateBatch(@Param("entities") List<CdcVolunteerActivity> entities);

    /**
     * 修改数据
     *
     * @param cdcVolunteerActivity 实例对象
     *
     * @return 影响行数
     */
    int update(CdcVolunteerActivity cdcVolunteerActivity);

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     *
     * @return 影响行数
     */
    int deleteById(@Param("id") String id);

    /**
     * 志愿者活动统计
     *
     * @return
     */
    @Select("SELECT COUNT( 1 ) total, SUM( IF(startTime > NOW(), 1, 0) ) notStarted, " +
            "SUM( IF(NOW() BETWEEN registerStartTime AND registerEndTime, 1, 0) ) inProgress, " +
            "SUM( IF(endTime < NOW(), 1, 0) ) ended FROM cdc_volunteer_activity " +
            "WHERE STATUS = 1 AND auditStatus = 1 AND delTag = 0 AND putawayStatus =1")
    CustomVolunteerActivityCount activityCount();

    /**
     * 获得排行榜
     *
     * @param number
     *
     * @return
     */
    List<CustomVolunteerActivity> getRanking(@Param("number") int number);

}
